package com.xx.happychatboot.serve.room.domain.entity;


import java.io.Serializable;
import java.util.Date;

import com.xx.happychatboot.serve.room.domain.enums.HotFlagEnum;
import com.xx.happychatboot.serve.room.domain.enums.RoomTypeEnum;
import io.mybatis.provider.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 房间表
 * </p>
 *
 * @author xiaoXuan
 * @since 2025-01-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity.Table("room")
public class Room implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @Entity.Column(id = true, remark = "主键", updatable = false, insertable = false)
    private Long id;

    /**
     * 房间类型 1群聊 2单聊
     */
    @Entity.Column("type")
    private Integer type;

    /**
     * 是否全员展示 0否 1是
     */
    @Entity.Column("hot_flag")
    private Integer hotFlag;

    /**
     * 群最后消息的更新时间（热点群不需要写扩散，只更新这里）
     */
    @Entity.Column("active_time")
    private Date activeTime;

    /**
     * 会话中的最后一条消息id
     */
    @Entity.Column("last_msg_id")
    private Long lastMsgId;

    /**
     * 额外信息（根据不同类型房间有不同存储的东西）
     */
    @Entity.Column("ext_json")
    private String extJson;

    /**
     * 创建时间
     */
    @Entity.Column("create_time")
    private Date createTime = new Date();

    /**
     * 修改时间
     */
    @Entity.Column("update_time")
    private Date updateTime = new Date();

    public static Room buildRoom(RoomTypeEnum typeEnum) {
        Room room = new Room();
        room.setType(typeEnum.getType());
        room.setHotFlag(HotFlagEnum.NOT.getType());
        room.setActiveTime(new Date());
        return room;
    }

}
